﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebComponents;
using WebComponents.Data;
using WebComponents.Security;
using System.Collections.Generic;
using GBIT.Web;

public partial class AlbumHinh : UserControlBase {  
  protected void Page_Load(object sender, EventArgs e) {
    this.AddModule = "TrangChu/AddFile.ascx";
    if (!Page.IsPostBack) {      
      cmbAlbum.Items.Clear();
      cmbAlbum.Items.Add(new ListItem("--Tất cả--", "0"));
      Global.LoadCategory("vi-VN", ref cmbAlbum, CatetoryType.File);
      LoadAlbum();
    }
    this.DeleteEnabled = true;
    this.AddEnabled = true;
    this.EditEnabled = true;        
    this.Title = "Thư viện hình ảnh";
  }
  protected override void OnDeleteRecord() {
    foreach (GridViewRow row in grvFileInfo.Rows) {
      if (((HtmlInputCheckBox)row.FindControl("chkSelect")).Checked) {
        FileController.Delete(ConvertType.ToInt(((HtmlInputCheckBox)row.FindControl("chkSelect")).Attributes["title"].ToString()));
      }
    }
    LoadAlbum();
  }
  private void LoadAlbum() {
    if (cmbAlbum.SelectedIndex == 0)
      grvFileInfo.DataSource = FileController.List();
    else
      grvFileInfo.DataSource = FileController.GetByCateID(ToInt(cmbAlbum.SelectedValue));
    grvFileInfo.DataBind();
  }
  protected void grvFileInfo_PageIndexChanging(object sender, GridViewPageEventArgs e) {
    List<FileInfo> files = null;
    if (cmbAlbum.SelectedIndex > 0)
      files = FileController.GetByCateID(ToInt(cmbAlbum.SelectedValue));
    else
      files = FileController.List();
    grvFileInfo.PageIndex = e.NewPageIndex;
    grvFileInfo.DataSource = files;
    grvFileInfo.DataBind();
  }
  protected void cmbAlbum_SelectedIndexChanged(object sender, EventArgs e) {
    LoadAlbum();
  }
}
